﻿using ComLib.ComFun;
using KWindow.KPageCore;
using Mp3Player;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

namespace IPCPages
{
    public partial class PageTakeNotice : PageControlBase
    {
        private Button buttonConfirm = null;

        private List<string> listGreetings = new List<string>();

        public PageTakeNotice()
        {
            InitializeComponent();
            SetProcessBase(ProcessTakeNotice.Instance);
        }

        private void InitGreetings()
        {
            string filePath = Path.Combine(GetAssemblyDirectory(), "Greetings.txt");
            List<string> list0 = IPCCom.ReadTextLines(filePath);
            listGreetings.Clear();
            listGreetings.AddRange(list0);
        }

        //初始化窗体数据
        public override void InitCtrls()
        {
            base.InitCtrls();
            InitGreetings();
            buttonCancel = GetControl<Button>("buttonCancel") as Button;
            buttonConfirm = GetControl<Button>("buttonConfirm") as Button;
            SetButtonDefaultStyles(buttonCancel);
            SetButtonDefaultStyles(buttonConfirm);
        }

        /// <summary>
        /// 初始化窗体数据
        /// </summary>
        public override void InitData()
        {
            AddSpeakDoneEvent(SpeakingDone);
        }

        /// <summary>
        /// 保存窗体数据(窗体本次做完后, 进入下一步之前)
        /// </summary>
        public override void UpdateData()
        {

        }

        /// <summary>
        /// 清理窗体数据(窗体本次做完后)
        /// </summary>
        public override void ClearData()
        {
            base.ClearData();
            AbortSpeak(); 
        }

        /// <summary>
        /// 窗体关闭时
        /// </summary>
        public override void Close()
        {

        }

        public override void StartWork()
        {
            Speak(listGreetings);
          
        }

        public override void StopWork()
        {
            base.StopWork();
        }

        private void buttonConfirm_Click(object sender, EventArgs e)
        {           
            StopCountdown();
            ClearData();
            Process.ToNext();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            StopCountdown();
            ClearData();
            Process.ToHome();
        }

        /// <summary>
        /// 处理问候音播报完成后的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void SpeakingDone(object sender, QueueSpeakingDoneEventArgs e)
        {
            //添加其他开始处理的代码
            StopCountdown();
            ClearData();
            Process.ToNext();
        }
    }
}
